import { defineStore } from 'pinia'
import router from '../router'

export const userInfoStore = defineStore('userInfoStore', {
  state: () => ({
    token: '',
    userInfo: {}
  }),
  actions: {
    setUserInfo(data) {
      this.userInfo = data
    },
    setToken(token) {
      this.token = token
    },
    clearToken() {
      this.token = ''
      router.push('/login')
    }
  },
  persist: {
    key: 'userInfo'
  }
})
